/**
 * 
 */
package com.hz.winnie.demands.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hz.winnie.demands.pojo.User;

/**
 * @description 用户DAO实现
 * @author winnie
 * @date 2011-4-23
 * @version 1.0
 */
public class UserDaoImpl extends SqlMapClientDaoSupport implements UserDao {

    /*
     * (non-Javadoc)
     * 
     * @see com.hz.winnie.demands.dao.UserDao#getUserById(java.lang.String)
     */
    @Override
    public User getUserById(String userId) {
	return (User) getSqlMapClientTemplate().queryForObject(
		"user.getUserById", userId);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.dao.UserDao#getUserByNameAndPassword(java.lang.
     * String, java.lang.String)
     */
    @Override
    public User getUserByNameAndPassword(String userName, String password) {
	Map<String, String> map = new HashMap<String, String>();
	map.put("userName", userName);
	map.put("password", password);
	return (User) getSqlMapClientTemplate().queryForObject(
		"user.getUserByNameAndPassword", map);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.hz.winnie.demands.dao.UserDao#getUsersByRole(java.lang.String)
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<User> getUsersByRole(String role) {
	return getSqlMapClientTemplate().queryForList("user.getUsersByRole",
		role);
    }

    @Override
    public int insert(User user) {
	return (Integer) getSqlMapClientTemplate().insert("user.insert", user);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hz.winnie.demands.dao.UserDao#edit(com.hz.winnie.demands.pojo.User)
     */
    @Override
    public void edit(User user) {
	getSqlMapClientTemplate().update("user.update", user);
    }
}
